package com.shenjian.workbench.controller;

import com.shenjian.commons.utils.Result;
import com.shenjian.workbench.entity.Activity;
import com.shenjian.workbench.service.ActivityService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.*;

/**
 * (Activity)表控制层
 *
 * @author makejava
 * @since 2022-07-02 16:45:46
 */
@Controller
@RequestMapping("/activity")
public class ActivityController {
    /**
     * 服务对象
     */
    @Autowired
    private ActivityService activityService;

    /**
     * 分页查询
     *
     * @param activity 筛选条件
     * @return 查询结果
     */
    @GetMapping("/page")
    @ResponseBody
    public Result listPage(@RequestParam(value = "pageNumber", defaultValue = "1") Integer pageNumber, @RequestParam(value = "pageSize", defaultValue = "3") Integer pageSize, Activity activity) {
        return Result.success(activityService.listPage(pageNumber, pageSize, activity));
    }

    /**
     * 通过主键查询单条数据
     *
     * @param id 主键
     * @return 单条数据
     */
    @GetMapping("/find/{id}")
    public Result queryById(@PathVariable("id") String id) {
        return Result.success(activityService.queryById(id));
    }

    /**
     * 新增数据
     *
     * @param activity 实体
     * @return 新增结果
     */
    @PostMapping("/save")
    @ResponseBody
    public Result add(@RequestBody Activity activity) {
        return Result.success(activityService.insert(activity));
    }

    /**
     * 编辑数据
     *
     * @param activity 实体
     * @return 编辑结果
     */
    @PutMapping("/edit")
    @ResponseBody
    public Result edit(@RequestBody Activity activity) {
        return Result.success(activityService.update(activity));
    }

    /**
     * 删除数据
     *
     * @param id 主键
     * @return 删除是否成功
     */
    @DeleteMapping("/remove/{id}")
    @ResponseBody
    public Result remove(@PathVariable String id) {
        return Result.success(activityService.deleteById(id));
    }

     /**
     * 删除数据
     *
     * @param ids 主键
     * @return 删除是否成功
     */
    @DeleteMapping("/remove")
    @ResponseBody
    public Result remove(String[] ids) {
        return Result.success(activityService.deleteBatch(ids));
    }

}

